// 流年似水还是似啥
#include <iostream>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int m, p, a, n;
struct {
  int l, r, v;
} tr[N * 4];
// [l, r] 区间
void build(int u, int l, int r) {
  tr[u] = {l, r, 0};
  if (l == r) return;
  int mid = l + r >> 1;
  build(u << 1, l, mid);
  build(u << 1 | 1, mid + 1, r);
}
// 每次修改后更新父节点
void pushup(int u) { tr[u].v = max(tr[u << 1].v, tr[u << 1 | 1].v); }
// 区间查询
int query(int u, int l, int r) {
  if (l <= tr[u].l && tr[u].r <= r) return tr[u].v;
  int mid = tr[u].l + tr[u].r >> 1;
  int v = 0;
  if (l <= mid) v = query(u << 1, l, r);
  if (r > mid) v = max(v, query(u << 1 | 1, l, r));
  return v;
}
// 单点修改
void modify(int u, int x, int v) {
  if (tr[u].l == tr[u].r)
    tr[u].v = v;
  else {
    int mid = tr[u].l + tr[u].r >> 1;
    if (x <= mid)
      modify(u << 1, x, v);
    else
      modify(u << 1 | 1, x, v);
    pushup(u);
  }
}
signed main() {
  cin >> m >> p;
  build(1, 1, m);
  for (int i = 1; i <= m; ++i) {
    char op;
    int x;
    cin >> op >> x;
    if (op == 'Q') {
      a = query(1, n - x + 1, n);
      cout << a << endl;
    } else {
      modify(1, n + 1, (x + a) % p);
      ++n;
    }
  }
}
